package logic

import (
	"context"
	"work_srv/workclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type JobcreateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewJobcreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *JobcreateLogic {
	return &JobcreateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *JobcreateLogic) Jobcreate(req *types.JobCreateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	login, err := l.svcCtx.WorkSrv.JobCreate(l.ctx, &workclient.JobCreateRequest{
		Name:        req.Name,
		Type:        req.Type,
		WorkAddress: req.WorkAddress,
		Info:        req.Info,
		Price:       float32(req.Price),
		Desc:        req.Desc,
	})
	if err != nil {
		return &types.Response{
			Mes:  err.Error(),
			Code: 500,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Mes:  "岗位添加成功",
		Code: 200,
		Data: login,
	}, nil
}
